import 'package:flutter/material.dart';
import 'package:xlp_github_app_flutter/redux/theme_redux.dart';
import 'package:xlp_github_app_flutter/redux/user_redux.dart';

import '../model/User.dart';
import 'gery_redux.dart';
import 'login_redux.dart';

/**
 * Redux全局State
 */

///全局Redux store 的对象，保存State数据
class AppState {
  ///用户信息
  User? userInfo;

  ///主题数据
  ThemeData? themeData;

  ///是否登录
  bool? login;

  ///是否变灰色
  bool grey;

  AppState({this.userInfo, this.themeData, this.login, this.grey = false});
}

///创建 Reducer
///源码中 Reducer 是一个方法 typedef State Reducer<State>(State state, dynamic action);
///我们自定义了 appReducer 用于创建 store
AppState appReducer(AppState state, action) {
  return AppState(
    ///通过 UserReducer 将 GSYState 内的 userInfo 和 action 关联在一起
    userInfo: UserReducer(state.userInfo, action),

    ///通过 ThemeDataReducer 将 GSYState 内的 themeData 和 action 关联在一起
    themeData: ThemeDataReducer(state.themeData, action),

    login: LoginReducer(state.login, action),

    ///通过 GreyReducer 将 GSYState 内的 grey 和 action 关联在一起
    grey: GreyReducer(state.grey, action),
  );
}
